﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using LeanEngine.Entity;
using System.Data.Common;
using System.Data;

namespace LeanEngine.Data
{
    /// <summary>
    /// Interface for database commands
    /// </summary>
    public interface IDataCommand
    {
        #region Method Members

        /// <summary>
        /// Prepare the bulk insert and execute it against the database.
        /// </summary>
        /// <typeparam name="T">The type of the collection elements.</typeparam>
        /// <param name="elementsList">The collection of System.Collections.Generic.IList of type <typeparamref name="T"/>.</param>
        void ExecuteBulkInsert<T>(IList<T> elementsList) where T : PlainEntity;

        /// <summary>
        /// Prepare the bulk insert and execute it against the database.
        /// </summary>
        /// <typeparam name="T">The type of the collection elements.</typeparam>
        /// <param name="elementsList">The collection of System.Collections.Generic.IList of type <typeparamref name="T"/>.</param>
        /// <param name="timeOut">The time in seconds to wait for the command to execute. The default is 0 seconds.</param>
        void ExecuteBulkInsert<T>(IList<T> elementsList, int timeOut) where T : PlainEntity;

        /// <summary>
        /// Creates a new instance of a System.Data.Common.DbParameter object.
        /// </summary>
        /// <param name="name">The name of the System.Data.Common.DbParameter.</param>
        /// <param name="value">The value of the parameter.</param>
        DbParameter NewParameter(string name, object value);

        /// <summary>
        /// Execute a SQL statement against a connection object.
        /// </summary>
        int ExecuteNonQuery();

        /// <summary>
        /// Execute a SQL statement against a connection object and return
        /// a System.Data.Common.DbDataReader using one of the System.Data.CommandBehavior
        /// values.
        /// </summary>
        /// <param name="behavior">An instance of System.Data.CommandBehavior.</param>
        IDataReader ExecuteReader(CommandBehavior behavior);

        /// <summary>
        /// Execute a SQL statement against a connection object and return
        /// a System.Data.Common.DbDataReader
        /// </summary>
        IDataReader ExecuteReader();

        /// <summary>
        /// Execute the query and returns the first column of the first row in the
        /// result set returned by the query. All other columns and rows are ignored.
        /// </summary>
        object ExecuteScalar();

        #endregion

        #region PropertyInfo Members

        /// <summary>
        /// Gets the list of LeanEngine.Data.Common.DataParameter class.
        /// </summary>
        DbParameterCollection Parameters { get; }

        /// <summary>
        /// Gets or sets the text command to run against the data source.
        /// </summary>
        string CommandText { get; set; }

        /// <summary>
        /// Indicates or specifies how the LeanEngine.Data.Common.DataCommand.CommandText 
        /// property is interpreted.
        /// </summary>
        CommandType CommandType { get; set; }

        /// <summary>
        /// Gets or sets the wait time before terminating the attempt to execute a command
        /// and generating an error.
        /// </summary>
        int CommandTimeout { get; set; }

        /// <summary>
        /// Gets or sets the database connection.
        /// </summary>
        DbConnection Connection { get; set; }

        /// <summary>
        /// Gets or sets the database transaction.
        /// </summary>
        DbTransaction Transaction { get; set; }

        #endregion
    }
}
